<template>
  <div>
    <!-- 表格数据 -->
    <el-card shadow="always" :body-style="{ padding: '20px' }">
      <el-table border stripe style="width: 100%" :data="list">
        <el-table-column type="index" label="序号" width="80">
        </el-table-column>
        <el-table-column prop="skuName" label="名称" width="width">
        </el-table-column>
        <el-table-column prop="skuDesc" label="描述" width="width">
        </el-table-column>
        <el-table-column prop="prop" label="默认图片" width="width">
          <template slot-scope="{ row, $index }">
            <div>
              <img
                :src="row.skuDefaultImg"
                :alt="row.skuName"
                style="width: 100px; height: 100px"
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="weight" label="重量" width="80">
        </el-table-column>
        <el-table-column prop="price" label="价格" width="80">
        </el-table-column>
        <el-table-column prop="prop" label="操作" width="width">
          <template slot-scope="{ row, $index }">
            <div>
              <el-button
               v-show="row.isSale"
                type="success"
                size="mini"
                icon="el-icon-sort-up"
                circle
                @click="downdatashop(row)"
              ></el-button>
              <el-button
              v-show="! row.isSale"
                type="primary"
                size="mini"
                icon="el-icon-sort-down"
                circle
                @click="updatashop(row)"
              ></el-button>
              <el-button
                type="warning"
                size="mini"
                circle
                icon="el-icon-edit"
                @click="showshopdetail(row)"
              ></el-button>
              <el-button
                type="info"
                size="mini"
                circle
                icon="el-icon-info"
                @click="maintenance(row)"
              ></el-button>
              <el-button type="danger" size="mini" 
              circle icon="el-icon-delete" @click="">

              </el-button>
              
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器-->
      <el-pagination :total="total" :current-page="page"
        :page-sizes="[3, 5, 8]" :page-size="limit"
        layout=" prev, pager, next, jumper,->,total, sizes"
        style="margin-top: 20px; textalign: center"
        :page-count="3" @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        @prev-click="handlePrevClick"
        @next-click="handleNextClick"
      ></el-pagination>
      <el-drawer
      style="font-size: 30px;color: #000;"
      title="详细信息"
      :visible.sync="drawer"
      :direction="direction"
      size="50%"
      :before-close="handleClose">

  <!-- 名称 -->
<el-row>
  <el-col :span="5">名称</el-col>
  <el-col :span="16">{{showshopdetaildata.skuName}}</el-col>
</el-row>
<!-- //描述 -->
<el-row>
  <el-col :span="5">描述</el-col>
  <el-col :span="16">{{showshopdetaildata.skuDesc}}</el-col>
</el-row>
<!-- 价格 -->
<el-row>
  <el-col :span="5">价格</el-col>
  <el-col :span="16">¥{{showshopdetaildata.price}}.00</el-col>
</el-row>
<!-- 平台属性 插槽 标签tap-->
<el-row>
  <el-col :span="5">平台属性</el-col>
  <el-col :span="16">
    <template>
      <el-tag type="success" size="mini" style="margin: 5px;" effect="dark" v-for="(item,index) in showshopdetaildata.skuAttrValueList" :key="index">
      {{ item.valueName }}
      </el-tag>
    </template>
  </el-col>
</el-row>
<!-- 商品图片 插槽 走马灯  -->
<el-row>
  <el-col :span="5">商品图片</el-col>
  <el-col :span="16">
  <template>
    <div>
      <el-carousel height="300px" width="300px" direction="vertical" :autoplay="false">
    <el-carousel-item v-for="item in showshopdetaildata.skuImageList" :key="item.id">
     <img :src="item.imgUrl" width="100%" height="100%" :alt="item.imgName">
    </el-carousel-item>
  </el-carousel>
    </div>
  </template>
  </el-col>
</el-row>
</el-drawer>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      list: [],
      limit: 5,
      page: 1,
      total: 0,
      showshopdetaildata:[],//抽屉数据
      drawer: false,//抽屉展示与隐藏
      direction: 'rtl',
    };
  },
  methods: {
    async getskudata() {
      const { page, limit } = this;
      let result = await this.$API.sku.getskudatalist(page, limit);
      console.log(result);
      if (result.code === 200) {
        this.list = result.data.records;
        this.total = result.data.total;
      }
    },
    //分页器的函数调用
    handleCurrentChange(pager) {
      this.page = pager;
      this.getskudata();
    },
    //每页多少条数据请求
    handleSizeChange(size) {
      this.limit = size;
      this.getskudata();
    },
    //前一页发起请求
    handlePrevClick() {
      this.page--;
      this.getskudata();
    },
    //后一页发起请求
    handleNextClick() {
      this.page++;
      this.getskudata();
    },
    //上架数据的回调
    async updatashop(row){
      row.isSale = 1;
      let result =await this.$API.sku.onsaveisshop(row.id)
      if(result.code === 200){
        this.$message({type:"success",message:"成功上架"})
      }
    },
    //下架数据的回调
    async downdatashop(row){
      row.isSale = 0;
      let result=await this.$API.sku.downsaveisshop(row.id)
      if(result.code === 200){
        this.$message({type:"warning",message:"已下架商品"})
      }
    },
    //info按钮
    maintenance(row){
      this.$message("开发维护中...")
    },
    //发起请求获取详细信息
    async showshopdetail(row){
      this.drawer=true;
      let result =await this.$API.sku.getshowshopdetail(row.id)
      console.log(result);
      if(result.code === 200){
        this.showshopdetaildata = result.data
      }
    },
    handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      }
  },
  components: {},
  mounted() {
    this.getskudata();
  },
};
</script>
<style scoped>
.el-row .el-col-5{
  font-size: 18px;
  text-align: right;
}
.el-col{
  margin: 10px 10px;
  font-size: 14px;
  align-content: center;
}
.el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 200px;
    margin: 0;
  }
  
  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }
</style>
